#include<bits/stdc++.h>
#define ONLINE_JUDGE
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 1.5e5 + 10, INF = 0x3f3f3f3f;

int n;
struct node
{
    int l, r;
    int len() { return r - l + 1; }
}a[N];
int f[N];

int find(int l, int r, int k)
{
    while (l < r) {
        int mid = (l + r + 1) >> 1;
        if (a[mid].r < k) l = mid;
        else r = mid - 1;
    }
    if (a[l].r < k) return f[l];
    else return 0;
}

void solve()
{
    cin >> n;
    for (int i = 1;i <= n;i++) cin >> a[i].l >> a[i].r;
    sort(a + 1, a + n + 1, [](node a, node b) {return a.r < b.r;});

    for (int i = 1;i <= n;i++)
        f[i] = max(f[i - 1], find(1, i - 1, a[i].l) + a[i].len());
    cout << f[n];
}

signed main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0);cout.tie(0);
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    //cin>>T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}